package demo15;

public class Test {

    // 字符串截取
    public static void main(String[] args) {
        String str = "helloworld" ;
        System.out.println(str.substring(5));
        System.out.println(str.substring(0, 5)); // 前闭后开
    }
    public static void main4(String[] args) {
        String str = "hello world hello bit" ;
        String[] result = str.split(" ",2) ;
        for(String s: result) {
            System.out.println(s);
        }
    }
    // 字符串替换
    public static void main3(String[] args) {
        String str1 = "hello world";
        String ret1 = str1.replace("ll","-");
        String ret2 = str1.replaceAll("l","-");
        String ret3 = str1.replaceFirst("l","!");
        System.out.println(str1);
        System.out.println(ret1);
        System.out.println(ret3);
    }

    // 字符串转数组
    public static void main2(String[] args) {
       String str1 = "hello world";
       char[] array = str1.toCharArray();
        for (char ch : array ) {
            System.out.println(ch);
        }
    }

    public static void main1(String[] args) {
        String str1 = "abc";
        String str2 = "abcdfg";
        String str3 = "ab";
//        System.out.println(str1.compareTo(str2));
//        System.out.println(str1.compareTo(str3));
        char a = str1.charAt(0);
        System.out.println(str2.lastIndexOf("fg",3));
    }
}
